package com.hh.usersystem.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.util.MessageException;
import com.hh.baseframework.util.base.BaseAction;
import com.hh.baseframework.util.model.ReturnModel;
import com.hh.usersystem.bean.usersystem.Organization;
import com.hh.usersystem.service.impl.OrganizationService;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class ActionOrg extends BaseAction<Organization> implements
		ModelDriven<Organization> {
	private Organization organization = new Organization();
	private String orgs;
	public Organization getModel() {
		return organization;
	}

	@Autowired
	private OrganizationService organizationService;

	public void queryPagingData() {
		this.returnResult(
				organizationService.queryPagingData(organization,
						this.getPageRange()));
	}

	public void queryOrgListByPidAndLx() {
		List<Organization> organizationList = organizationService
				.queryOrgListByPidAndLx(organization, paramsMap.get("node"));
		this.returnResult(organizationList);
	}
	
	public void queryOrgAndUsersList() {
		List<Object> organizationList = organizationService
				.queryOrgAndUsersList(organization.getNode());
		this.returnResult(organizationList);
	}

	public void queryOrgListByPid() {
		List<Organization> organizationList = organizationService
				.queryOrgListByPid(organization.getNode(),orgs);
		this.returnResult(organizationList);
	}

	public void findObjectById() {
		Organization hhXtCd = organizationService
				.findObjectById(this.organization.getId());
		this.returnResult(hhXtCd);
	}

	public void deleteByIds() {
		organizationService.deleteByIds(this.getIds());
	}

	public void save() {
		try {
			Organization hhXtYh = organizationService.save(this.organization);
			this.getResultMap().put("object", hhXtYh);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public String getOrgs() {
		return orgs;
	}

	public void setOrgs(String orgs) {
		this.orgs = orgs;
	}

}
